﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

namespace EDTS.Weixin.Submits
{
    public class Messages
    {
        /// <summary>
        /// 消息发送URL
        /// </summary>
        public static string Url
        {
            get
            {
                return "https://qyapi.weixin.qq.com/cgi-bin/message/send";
            }
        }
        /// <summary>
        /// 发送单图文消息
        /// </summary>
        /// <param name="token"></param>
        /// <param name="username"></param>
        /// <param name="title"></param>
        /// <param name="description"></param>
        /// <param name="url"></param>
        /// <param name="picurl"></param>
        public static JObject SendNews(string token, string username,string description)
        {
            var articles = Newtonsoft.Json.JsonConvert.DeserializeObject(description);
            var obj = new
            {
                touser = username,
                msgtype = "news",
                agentid = 0,
                news = new
                {
                    articles = articles
                }
            };
            return Submit.Post(token, Url, obj);
        }
        /// <summary>
        /// 发送文本消息
        /// </summary>
        /// <param name="token"></param>
        /// <param name="username"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public static JObject SendText(string token, string username, string content,bool safe=false)
        {
            var obj = new
            {
                touser = username,
                msgtype = "text",
                agentid = 0,
                text = new
                {
                    content = content
                },
                safe = safe ? 1 : 0
            };
            return Submit.Post(token, Url, obj);
        }
    }
}
